package com.sinosoft.perfect.system._roleBusiness.dataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TRoleBusiness;

public class RoleBusinessGridDataFormat_DHX implements IRoleBusinessGridDataFormat {

	@Override
	public String dataFormatRoleBusinessGrid(List<TRoleBusiness> roleBusinessList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(roleBusiness.getRoleBusinessId());
				cell2.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(roleBusiness.getRoleBusinessId());
				cell3.setContent(roleBusiness.getNote());
				infos.add(cell3);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatRoleBusinessGridForUser(List<TRoleBusiness> roleBusinessList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell1);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatRoleBusinessGridForBindUser(List<TRoleBusiness> roleBusinessList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(roleBusiness.getRoleBusinessId());
				cell2.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(roleBusiness.getRoleBusinessId());
				cell3.setContent(roleBusiness.getNote());
				infos.add(cell3);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatRoleBusinessGridForBindUser(List<TRoleBusiness> roleBusinessList, List<String> roleBusinessIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				if (roleBusinessIds != null && roleBusinessIds.size() > 0) {
					for (int j = 0; j < roleBusinessIds.size(); j++) {
						if (roleBusiness.getRoleBusinessId().equals(roleBusinessIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(roleBusiness.getRoleBusinessId());
				cell2.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(roleBusiness.getRoleBusinessId());
				cell3.setContent(roleBusiness.getNote());
				infos.add(cell3);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}
	
	@Override
	public String roleBusinessGridForBindAUnitUsers(List<TRoleBusiness> roleBusinessList, List<String> roleBusinessIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				if (roleBusinessIds != null && roleBusinessIds.size() > 0) {
					for (int j = 0; j < roleBusinessIds.size(); j++) {
						if (roleBusiness.getRoleBusinessId().equals(roleBusinessIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell1);

			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	
	@Override
	public String roleBusinessGridForBindAUnit(List<TRoleBusiness> roleBusinessList, List<String> roleBusinessIds) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);

		if (roleBusinessList != null && roleBusinessList.size() > 0) {
			for (int i = 0; i < roleBusinessList.size(); i++) {
				TRoleBusiness roleBusiness = roleBusinessList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(roleBusiness.getRoleBusinessId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", roleBusiness.getRoleBusinessId());
				if (roleBusinessIds != null && roleBusinessIds.size() > 0) {
					for (int j = 0; j < roleBusinessIds.size(); j++) {
						if (roleBusiness.getRoleBusinessId().equals(roleBusinessIds.get(j))) {
							properties.put("select", "true");
						}
					}
				}
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(roleBusiness.getRoleBusinessId());
				cell1.setContent(roleBusiness.getRoleBusinessName());
				infos.add(cell1);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}
}
